import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {DomSanitizer} from '@angular/platform-browser';
import {TypeService} from '../../../../shared/service/type.service';
import {HttpParams} from '@angular/common/http';
import {markdown} from 'markdown';

@Component({
  selector: 'app-type-article-detail',
  templateUrl: './type-article-detail.component.html',
  styleUrls: ['./type-article-detail.component.scss']
})
export class TypeArticleDetailComponent implements OnInit {
  article;

  html;
  constructor(
    public router: Router,
    public activeRoute: ActivatedRoute,
    private domSanitizer: DomSanitizer,
    private typeService: TypeService
  ) { }

  ngOnInit() {
    this.activeRoute.params.subscribe((res) => {
      const params = new HttpParams().set('id', res.id);
      this.typeService.getArticleDetail(params).subscribe((result) => {
        this.article = result;
        // this.article.createTime = new Date();
        this.html = markdown.toHTML(this.article.detail);
        this.html = this.domSanitizer.bypassSecurityTrustHtml(this.html);
      });
    });
  }

}
